package de.lgohlke.compress;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.lgohlke.collection.SavedSpace;

/**
 * default compressor, dont convert the input values
 * 
 * @author lars
 * @param <T>
 * @version $Id: $
 */
public class NullCompressor<T> implements ICompressor<T>
{
  private final static Logger log = LoggerFactory.getLogger(NullCompressor.class);

  /**
   * <p>
   * compress.
   * </p>
   * 
   * @param value
   *          a T object.
   * @param <T>
   *          a T object.
   * @return a {@link de.lgohlke.compress.CompressableValue} object.
   */
  @Override
  public CompressableValue<T> compress(final T value)
  {
    return new CompressableValue<T>(value, false);
  }

  /** {@inheritDoc} */
  @Override
  public T decompress(final CompressableValue<T> vo)
  {
    return vo.getValue();
  }

  /** {@inheritDoc} */
  @Override
  public SavedSpace savedSpace(final CompressableValue<T> vo)
  {
    SavedSpace ss = new SavedSpace();
    T _value = vo.getValue();

    if (_value != null)
    {
      if (vo.getValue() instanceof String)
      {
        ss.setRawSize(((String) _value).length());
      }
      else if (vo.getValue() instanceof byte[])
      {
        ss.setRawSize(((byte[]) _value).length);
      }
      else
      {
        if (log.isDebugEnabled())
        {
          log.debug("not supported datatype : " + _value.getClass());
        }
      }
    }
    ss.setSavedSize(ss.getRawSize());

    return ss;
  }
}
